package com;


import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class MagicXdCode {
    public static void main(String[] args) {
        //构建代码生成器对象
        AutoGenerator autoGenerator = new AutoGenerator();

        //配置策略
        //1、全局配置
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setOutputDir(System.getProperty("user.dir") + "/src/main/java");
        globalConfig.setAuthor("magicXd");
        globalConfig.setOpen(false);
        globalConfig.setFileOverride(false);

        autoGenerator.setGlobalConfig(globalConfig);


        //2、数据源配置
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setUrl("jdbc:mysql://localhost:3306/ant?useUnicode=true&useSSL=false&characterEncoding=utf8");
        dataSourceConfig.setDriverName("com.mysql.jdbc.Driver");
        dataSourceConfig.setUsername("root");
        dataSourceConfig.setPassword("147258");

        autoGenerator.setDataSource(dataSourceConfig);

        // 3、包的配置
        PackageConfig packageConfig = new PackageConfig();
        packageConfig.setModuleName("magicXdCode");
        packageConfig.setParent("com.magicXd");
        packageConfig.setEntity("entity");
        packageConfig.setService("service");
        packageConfig.setController("controller");

        autoGenerator.setPackageInfo(packageConfig);

        //4、策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        strategy.setSuperEntityClass("com.baomidou.ant.common.BaseEntity");
        strategy.setEntityLombokModel(true);
        strategy.setRestControllerStyle(true);
        autoGenerator.setStrategy(strategy);



    }
}
